<template>
  <div class="app-container">
    <!-- 操作工具栏 -->
    <el-card class="toolbar-card">
      <el-row :gutter="16" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="Plus"
            class="toolbar-button is-primary"
            @click="handleAdd"
          >新建文件夹</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            icon="Delete"
            :disabled="multiple"
            class="toolbar-button is-danger"
            @click="handleDelete"
          >删除</el-button>
        </el-col>
      </el-row>
    </el-card>

    <!-- 文件夹表格 -->
    <el-card>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="name" label="文件夹名称" />
        <el-table-column prop="path" label="路径" />
        <el-table-column prop="fileCount" label="文件数量" width="100" />
        <el-table-column prop="size" label="大小" width="100" />
        <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
          <template #default="scope">
            <div class="table-operation-wrapper">
              <el-button
                type="primary"
                icon="Edit"
                @click="handleUpdate(scope.row)"
                class="table-operation-button is-primary"
                size="small"
              >修改</el-button>
              <el-button
                type="danger"
                icon="Delete"
                @click="handleDelete(scope.row)"
                class="table-operation-button is-danger"
                size="small"
              >删除</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'

const loading = ref(false)
const ids = ref([])
const multiple = ref(true)

const tableData = ref([
  {
    id: 1,
    name: '我的文档',
    path: '/documents',
    fileCount: 15,
    size: '2.5MB'
  }
])

// 多选框选中数据
const handleSelectionChange = (selection) => {
  ids.value = selection.map(item => item.id)
  multiple.value = !selection.length
}

// 新增按钮操作
const handleAdd = () => {
  console.log('新建文件夹')
  ElMessage.info('新建文件夹功能')
}

// 修改按钮操作
const handleUpdate = (row) => {
  console.log('修改文件夹:', row.id)
  ElMessage.info('修改文件夹功能')
}

// 删除按钮操作
const handleDelete = (row) => {
  const folderIds = row?.id ? [row.id] : ids.value
  ElMessageBox.confirm('是否确认删除选中的文件夹数据项？', '警告', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    console.log('删除文件夹:', folderIds)
    ElMessage.success('删除成功')
  }).catch(() => {})
}

onMounted(() => {
  // 初始化数据
})
</script>

<style lang="scss" scoped>
.toolbar-card {
  margin-bottom: 16px;
}

.mb8 {
  margin-bottom: 8px;
}
</style>
